package com.sctu.adapter;

import android.app.Activity;
import android.content.Context;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.sctu.EMSApp.R;
import com.sctu.bean.SurroundBean;
import com.sctu.http.UrlConfig;
import com.sctu.httpvollry.GetVolleyHttp;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fll on 2015/12/10.
 */
public class SurroundAdapter extends BaseAdapter {

    private List<SurroundBean.Results> viewList;
    private Activity context;

    public SurroundAdapter(List<SurroundBean.Results> viewList, Activity context) {
        this.viewList = viewList;
        this.context = context;
    }

    @Override
    public int getCount() {
        if (viewList != null && viewList.size() > 0) {
            return viewList.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_scenictour_round, null);

        TextView textOrder = (TextView) view.findViewById(R.id.item_scenicTour_round_orderText);
        TextView textContent = (TextView) view.findViewById(R.id.item_scenicTour_round_contentText);
        ImageView imageView = (ImageView) view.findViewById(R.id.item_scenicTour_round_image);

        GetVolleyHttp.getInstance(context).setImageLoader(imageView,R.drawable.temp_two,R.drawable.temp_two, UrlConfig.URL + viewList.get(position).getPath());


        textOrder.setText(position + 1 + "");
        textContent.setText(viewList.get(position).getTitle() + viewList.get(position).getContent().substring(0, 30) + "...");

        SpannableStringBuilder builder = new SpannableStringBuilder(textContent.getText().toString());
        ForegroundColorSpan span = new ForegroundColorSpan(context.getResources().getColor(R.color.gold));
        builder.setSpan(span, 0, viewList.get(position).getTitle().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.setSpan(new AbsoluteSizeSpan(42), 0, viewList.get(position).getTitle().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        textContent.setText(builder);
        return view;
    }
}
